package com.ctp.bean;

public class FormBean {

	private String seqNum = null;

	private String contrName = null;

	private boolean buySellInd = false;

	private boolean openCloseInd = false;

	private double formPrice = 0;

	private int formVolume = 0;

	private int frontId = 0;

	private int sessionId = 0;

	private String exchangeId = null;

	private String formNum = null;

	private String formTime = null;

	private char formStatus = '-';

	private String formStatusMsg = null;

	private double bargainAmt = 0;

	private int bargainVolume = 0;

	private double originDiffPrice = 0;

	private double originLeg1Price = 0;

	private double originLeg2Price = 0;

	private FormBean relativeForm = null;

	public FormBean(String seqNum) {
		this.seqNum = seqNum.trim();
	}

	public void setFormBasicInfo(String contrName, boolean buySellInd,
			boolean openCloseInd, double formPrice, int formVolume) {
		this.contrName = contrName.trim();
		this.buySellInd = buySellInd;
		this.openCloseInd = openCloseInd;
		this.formPrice = formPrice;
		this.formVolume = formVolume;
	}

	public void setFormReturnInfo(String formNum, String formTime,
			String formStatus, String formStatusMsg) {
		this.formNum = formNum.trim();
		this.formTime = formTime.trim();
		this.formStatus = formStatus.toCharArray()[0];
		this.formStatusMsg = formStatusMsg.trim();
	}

	public void setFormClientInfo(String frontId, String sessionId,
			String exchangeId) {
		this.frontId = Integer.parseInt(frontId);
		this.sessionId = Integer.parseInt(sessionId);
		this.exchangeId = exchangeId.trim();
	}

	public void updateBargainInfo(double price, int volume) {
		bargainAmt += price * volume;
		bargainVolume += volume;
	}

	public void setOriginDiffPrice(double originDiffPrice,
			double originLeg1Price, double originLeg2Price) {
		this.originDiffPrice = originDiffPrice;
		this.originLeg1Price = originLeg1Price;
		this.originLeg2Price = originLeg2Price;
	}

	public void setRelativeForm(FormBean relativeForm) {
		this.relativeForm = relativeForm;
	}

	public FormBean getRelativeForm() {
		return relativeForm;
	}

	public double getOriginDiffPrice() {
		return originDiffPrice;
	}

	public double getOriginLeg1Price() {
		return originLeg1Price;
	}

	public double getOriginLeg2Price() {
		return originLeg2Price;
	}

	public double getBargainPrice() {
		return bargainVolume == 0 ? 0 : bargainAmt / bargainVolume;
	}

	public boolean isTotallyBargain() {
		return formVolume == bargainVolume
				&& formStatus == TOTALLY_BARGAINED_STATUS;
	}

	public boolean isFormDeleted() {
		return formStatus == FORM_DELETED_STATUS;
	}

	public int getBargainVolume() {
		return bargainVolume;
	}

	public String getFormStatusMsg() {
		return formStatusMsg;
	}

	public int getFrontId() {
		return frontId;
	}

	public int getSessionId() {
		return sessionId;
	}

	public String getExchangeId() {
		return exchangeId;
	}

	public String getFormNum() {
		return formNum;
	}

	public String getFormTime() {
		return formTime;
	}

	public boolean isOpenCloseInd() {
		return openCloseInd;
	}

	public String getContrName() {
		return contrName;
	}

	public boolean isBuySellInd() {
		return buySellInd;
	}

	public double getFormPrice() {
		return formPrice;
	}

	public int getFormVolume() {
		return formVolume;
	}

	public String getSeqNum() {
		return seqNum;
	}

	private static final char TOTALLY_BARGAINED_STATUS = '0';

	private static final char FORM_DELETED_STATUS = '5';

}
